package com.sc.service.impl.vehicle;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.domain.VehiclePosition;
import com.sc.domain.VehicleRegion;
import com.sc.dto.VehiclePositionPageDTO;
import com.sc.mapper.vehicle.VehiclePositionMapper;

import com.sc.service.vehicle.IVehiclePositionService;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;

@Service
public class IVehiclePositionServiceImpl extends ServiceImpl<VehiclePositionMapper, VehiclePosition>
        implements IVehiclePositionService {

    @Override
    public Boolean insertPosition(VehiclePosition vehiclePosition) {
        return save(vehiclePosition);
    }

    @Override
    public Page<VehiclePosition> showRegions(Integer pageNum, Integer pageSize,String region,Integer status) {
        Page<VehiclePosition> page = Page.of(pageNum,pageSize);
        QueryWrapper<VehiclePosition> wrapper = new QueryWrapper<>();
        if (region != null)
        {
            wrapper.like("no",region);
        }
        if (status != null)
        {
            wrapper.like("status",status);
        }
        page(page,wrapper);
        return page;
    }

    @Override
    public Page<VehiclePosition> listByStatusAndNo(VehiclePositionPageDTO pageDTO) {
        Integer pageNum = pageDTO.getPageNum();
        Integer pageSize = pageDTO.getPageSize();
        Page<VehiclePosition> page = Page.of(pageNum,pageSize);
        Integer examineResult = pageDTO.getExamineResult();
        String no = pageDTO.getNo();
        QueryWrapper<VehiclePosition> wrapper = new QueryWrapper<>();
        if (examineResult != null)
        {
            wrapper.eq("examine_result",examineResult);
        }
        if (no != null)
        {
            wrapper.like("no",no);
        }
        page(page,wrapper);
        return page;
    }
}
